package testing;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class LineCounter {
	private static long count = 0;
	
	public static void countFolder(File file, String suffix)
	{
		countFolder(file, suffix, "\\/");
	}
	
	public static void countFolder(File file, String suffix, String exclude)
	{
		if(file.isDirectory())
		{
			for(File f : file.listFiles())
				countFolder(f, suffix, exclude);
		}
		else
		{
			if(file.getName().endsWith(suffix) && 
					!file.getName().endsWith(exclude))
			{
				Scanner s;
				try {
					s = new Scanner(file);
					long fc = 0;
					while(s.hasNext())
					{
						s.nextLine();
						fc++;
					}
					s.close();
					System.out.println(file.getName() + " : " + fc);
					count += fc;
				} catch (FileNotFoundException e) {}
			}
		}
	}
	
	public static void main(String[] args) {
		File f = new File("src");
		if(f != null)
			countFolder(f, ".java");
		System.out.println();
		System.out.println("Total lines : " + count);
	}

}
